<style lang="less">

</style>

<template>
  <div class="nCoV-list-container">
    <div v-if="type === 'search'">
      <van-search v-model="searchValue" placeholder="车厢号查询" @search="onSearch" />
      <news-card v-for="item in searchList" :key="item.id" :title="`${item.t_no}`" :value="`出发: ${item.t_pos_start}--`" :desc="`到达: ${item.t_pos_end}--`" />
    </div>
    <news-card v-else v-for="item in list" :key="item.id" :id="item.id" :title="item.title" :value="item.date" />
    <van-divider >没有更多了</van-divider>
  </div>
</template>

<script>
import NewsCard from '../../components/newsCard'
import NCoVApi from '../../api/nCoV'
export default {
  components: {
    NewsCard
  },
  data() {
    return {
      list: [],
      searchValue: '',
      searchList: []
    }
  },
  computed: {
    type() {
      // main 主推  refutes 辟谣  inspection 自查  prevention 预防  search 寻人
      return this.$route.query.type || ''
    }
  },
  methods: {
    onSearch(value) {
      if (value) {
        this.searchList = this.list.filter(item => item.t_no.indexOf(value) > 0)
      } else {
        this.searchList = this.list
      }
    },
    async getArticleList() {
      let res = null
      switch (this.type) {
        case 'main':
          res = await NCoVApi.GetNCoVMainArticleList()
          break
        case 'refutes':
          res = await NCoVApi.GetRefutesArticleList()
          break
        case 'inspection':
          res = await NCoVApi.GetInspectionsArticleList()
          break
        case 'prevention':
          res = await NCoVApi.GetPreventionArticleList()
          break
        case 'search':
          var result = await NCoVApi.GetSeachList()
          res = {
            code: 0,
            data: {
              list: result.data
            },
            msg: 'ok'
          }
          this.searchList = result.data
          break
      }
      if (res) {
        this.list = res.data.list
      }
    }
  },
  created() {
    this.getArticleList()
  }
}
</script>
